import React, { useEffect, useState } from "react"
import { useMainContext } from "./MainContext"

function useFormField({
    fieldPath,
    onChanged
}){

    const [, updater] = useState({});

    let formData = useMainContext();
    
    return {
        value: formData?.[fieldPath],
        onChange: function(value) {

            //更新上下文
            formData[fieldPath] = value;

            //触发当前字段更新
            updater({});
        }
    }

}

export {
    useFormField
}